const getters = {
  //系统编码代号
  getSystemCode: (state) => {
    // return "state.common.systemCode"
    return state.common.systemCode;
  },
  setSystemCode: (state) => (code) => {
    state.common.systemCode = code;
  },
  menuPictures: (state) => {
    return state.common.menuPictures;
  },
  orgList: (state) => {
    return state.user.mineUserInfo.orgVoList.map((item) => {
      const obj = {
        label: `${item.levelPathName}/${item.name}`,
        value: item.id,
      };
      return obj;
    });
  },
  leaderOrgList: (state) => {
    if (state.user.userInfo.agent) {
      return state.user.userInfo.orgVoList.map((item) => {
        const obj = {
          label: `${item.levelPathName}/${item.name}`,
          value: item.id,
        };
        return obj;
      });
    } else {
      return false;
    }
  },
  userName: (state) => {
    let name = state.user.mineUserInfo.name;
    return name.substr(name.length - 2);
  },
  appList: (state) => state.user.appListData,
  appAuthList: (state) => {
    return state.user.mineUserInfo.appSimpleBeanList.map((item) => {
      const obj = {
        label: item.appName,
        value: item.appId,
      };
      return obj;
    });
  },
  mineAppList: (state) => {
    return state.user.mineUserInfo.appSimpleBeanList.map((item) => {
      const obj = {
        label: item.appName,
        value: item.appMark,
      };
      return obj;
    });
  },
  idenList: (state) => {
    let list = [];
    if (state.user.mineUserInfo.leaderUserVos) {
      list = state.user.mineUserInfo.leaderUserVos.map((item) => {
        const obj = {
          label: `${item.leaderName}的委托人`,
          value: item.leader,
        };
        return obj;
      });
    }
    list.unshift({
      label: "本人",
      value: state.user.mineUserInfo.account,
    });
    return list;
  },
  getMenuPicture: (state) => (code) => {
    let data = state.user.menuPictures;
    for (let i in data) {
      if (data[i].code == code) {
        return data[i];
        break;
      }
    }
    return "";
  },
  //当前水司信息
  currentAppInfo: (state) => {
    let data = state.user.appListData.find((item) => {
      return item.value == state.user.currentInfo.currDs;
    });
    return data;
  },
  //可操作的路由
  addRouters: (state) => state.permission.addRouters,
  userInfo: (state) => state.user.userInfo,
  mineUserInfo: (state) => state.user.mineUserInfo,
  currentInfo: (state) => state.user.currentInfo, //当前的水司，组织，身份
  currentOrgInfo: (state) => {
    let data = state.user.userInfo.orgVoList.find((item) => {
      return item.id == state.user.currentInfo.currOrg;
    });
    return data;
  },
  avatarUrl: (state) => state.user.avatarUrl,
  userSignType: (state) => {
    let source = localStorage.getItem("currDs");
    let appSimpleBeanList =
      state.user.userInfo.userOwnJurisdictionBean.appSimpleBeanList;
    for (let i in appSimpleBeanList) {
      if (appSimpleBeanList[i].appMark == source) {
        return appSimpleBeanList[i].sign;
      }
    }
    return null;
  },
  firstNav: (state) => state.user.allAuth.firstNav,
  appListData: (state) => state.user.appListData,
  // 权限
  allAuth: (state) => state.user.allAuth,
  dictData: (state) => state.common.dictData,
  vendorList: (state) => state.common.vendorList, //厂商
  brandList: (state) => state.common.brandList, //品牌
  // 是否启用二级升一级
  // isSecondToFirst: state => {
  //     return false
  //     // return true
  // },
  // 字典
  dirtData: (state) => (code, valType = "itemCode") => {
    let data = [];
    if (code) {
      data = state.common.dictData[code] || [];
    }
    const arr = data.map((i) => {
      let obj = {};
      obj.label = i.value;
      obj.value = i.key;
      return obj;
    });
    return arr;
  },
  // 寻找字典name
  fineDirtDataName: (state) => (code, value) => {
    let data = code ? state.common.dictData[code] : [];
    data = data || [];
    let obj = data.find((i) => i.key == value);
    return obj ? obj["value"] : value;
  },
  /**一级菜单 */
  firstNav: (state) => {
    let firstList = [];
    state.user.allAuth &&
      state.user.allAuth.firstNav &&
      (firstList = state.user.allAuth.firstNav);
    return firstList;
  },
  /**二级菜单 */
  secondNavObj: (state) => {
    let secondNav = {};
    state.user.allAuth &&
      state.user.allAuth.secondNav &&
      (secondNav = state.user.allAuth.secondNav);
    return secondNav;
  },
  /**当前一级下的二级菜单权限 */
  currentSecondNav: (state) => (pageCode) => {
    let secondNav = state.user.allAuth.secondNav;
    // let indexStr = '"code":"' + pageCode + '"';
    // for (const key in secondNav) {
    //   let arr = secondNav[key];
    //   if (JSON.stringify(arr).indexOf(indexStr) != -1) {
    //     return arr;
    //   }
    // }
    return secondNav[pageCode] || [];
  },
  /**当前页面的按钮权限 */
  currentButtonAuth: (state) => {
    return state.user.currentButtonAuth;
  },
  
  getCurrentBtnAuth: (state) => (pageCode) => {
    let btnAuth = [];
    if (state.user.allAuth && state.user.allAuth.btnAuth) {
      state.user.allAuth.btnAuth.forEach((item) => {
        if (item.menuCode == pageCode) {
          btnAuth.push(item.funcCode);
        }
      });
    }
    return btnAuth;
  },
  /**
   * 判断是否有菜单权限
   */
  isHaveMenuAuth: (state) => (code) => {
    let res = state.user.allAuth.menuList.find((item) => {
      return item.menuCode == code;
    });
    return res;
  },
  /**判断按钮是否有权限 */
  isBtnAuth: (state) => (btnCode) => {
    let btnArr = state.user.currentButtonAuth || [];
    return btnArr.includes(btnCode);
  },
  //获取表格类型
  tableTypes: (state) => {
    return state.common.tableTypes;
  },
  //获取Cookie的值
  getCoolieData: (state) => (keyName) => {
    let data = document.cookie;
    if (data.length > 0) {
      let startNum = data.indexOf(keyName + "=");
      if (startNum != -1) {
        startNum = startNum + keyName.length + 1;
        let endNum = data.indexOf(";", startNum);
        if (endNum == -1) endNum = data.length;
        return unescape(data.substring(startNum, endNum));
      }
    }
    return "";
  },
  getUndoData: (state) => {
    return state.commonData.undoData;
  },
  //获取勾选的不巡视点
  getNoPatrolPoint:(state)=>()=>{
    return state.common.noPartol
  },
  // 获取多语言
  getLanguage:({languages:{languageData,language}})=>(code)=>{
    let obj;
    try {
      obj=languageData.get(code)
    } catch (error) {
      obj=""
    }
    return languageData.get(code)[language]
  },
  getLanguageType:({languages:{languageType}})=>(code)=>{
    return languageType
  }
};
export default getters;
